home *** CD-ROM | disk | FTP | other *** search
- // Ken's Cursing
- // version 1.0.1
- // by Ken Long <kenlong@netcom.com>
- // updated for CW7 and THINK 7 on 951201
-
- //• --------------------------------------------------------------- •//
- //• An itty bitty bytes™ novice Mac C programmer demo of •//
- //• SPINNING A COLOR CURSOR - without a VBL task. •//
- //• •//
- //• Kenneth A. Long •//
- //• aka "itty bitty bytes™" •//
- //• kenlong@netcom.com •//
- //• 18 November 1995 •//
- //• •//
- //• This is the simplest way to spin a color cursor. •//
- //• --------------------------------------------------------------- •//
-
- #define over qd.screenBits.bounds.right
- #define down qd.screenBits.bounds.bottom
-
- CCrsrHandle apple[20]; //• 20 Macintosh apples.
- Boolean hues;
- Rect windRect;
- WindowPtr ibbWind;
-
- //• Prototypes:
- void SetMyCursor (CCrsrHandle cCrsr);
- CCrsrHandle GetMyCursor (short cursID);
- void InitSpinner (void);
- void Rotate (void);
- void InitMacintosh (void);
- void main (void);
-
- //• Routines:
-
- #define rotateTicks 8L /* Minimum time, in ticks (1/60 sec.) */
- short crsr; /* current cursor index */
- long lasttime; /* tickcount from previous call */
-
- //• --------------------------------------------------------------- •//
- //• Sniped from the "SpinCursor" Pascal source.
- //• If the Mac has color, it sets the color cursors. If not, it
- //• does NOT set 'CURS' resources - only the B/W of the 'crsr' res's.
- //• Try setting "hues" to false, in InitMac ().
-
- void SetMyCursor(CCrsrHandle cCrsr)
- {
- if (hues)
- SetCCursor(cCrsr);
- else
- SetCursor((CursPtr)(&cCrsr[0]->crsr1Data)[0]);
- }
-
- //• --------------------------------------------------------------- •//
- //• This *GETS* the resources as prescribed by the "InitSpinner"
- //• routine. The ID number is passed here, and the color res. is
- //• passed back IF the Mac has color. If not, a handle to the
- //• resource is gotten.
-
- CCrsrHandle GetMyCursor(short cursID)
- {
- Handle h;
-
- if (hues)
- {
- //• GetCIcon doesn't release the resource, so let's do that!
- h = GetResource('crsr', cursID);
- ReleaseResource(h);
- return (GetCCursor(cursID));
- }
- else
- return ((CCrsrHandle) GetResource('crsr', cursID));
- }
-
- //• --------------------------------------------------------------- •//
- //• This tells GetMyCursor which resources to get. We have 20, in
- //• this case.
- //• You put the *quantity* of 'crsr' resources you want to
- //• display into the center section of the 'for' loop.
- //• If you have a different batch of cursors, for a different action,
- //• then use two 'for' loops here - one for each batch. Then use an
- //• 'if' statement to chosse them and call "InitSpinner" again. The
- //• resources are released by GetMyCursor, so it should not eat RAM.
-
- void InitSpinner ()
- {
- short i;
- crsr = 0;
- lasttime = 0L;
-
- for (i = 0; i < 20; i++)
- apple[i] = GetMyCursor(128 + i); //• 'i' is 0 on first pass.
- }
-
-
- // void InitSpinner () //• Alternate InitSpinner.
- // {
- // short i;
- // crsr = 0;
- // lasttime = 0L;
- //
- // if (progress) //• A boolean...
- // for (i = 0; i < 20; i++) //• First has 20.
- // apple[i] = GetMyCursor(128 + i); //• First set of ID's.
- //
- // if (idling) //• Same here...
- // for (i = 0; i < 20; i++)
- // apple[i] = GetMyCursor(148 + i); //• Another set.
- // }
-
-
- //• --------------------------------------------------------------- •//
- //• Puts up the Rotating Apple, and rotates it if previously
- //• present, and enough time has elapsed since the last rotation.
- //• It's called, in this case, in each pass through the main event
- //• loop. It's called, rotates to the next ID, unless the next one
- //• is out of range, in which case it reverts back to the first one.
- //• But you will want to call it from a 'do/while' loop
-
- void Rotate()
- {
- long time;
-
- time = TickCount();
-
- if (time < lasttime)
- return;
- else
- {
- lasttime = time + rotateTicks;
- crsr++;
-
- //• "crsr" MUST total the quantity plus 0. In this case,
- //• 0 + 19 = 20, or our total. If you said "if (crsr > 20)"
- //• it would crash because we only have 20 'crsr's.
- if (crsr > 19)
- crsr = 0;
- SetMyCursor(apple[crsr]);
- }
- }
-
- void InitMacintosh(void)
- {
- SysEnvRec world;
-
- MaxApplZone();
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- TEInit();
- InitCursor();
-
- //• Check for color.
- hues = false;
- if ( SysEnvirons(1, &world) == noErr ) //• Comment out this...
- hues = world.hasColorQD; //• ...and this for B/W.
-
- windRect.top = down / 2 - 10;
- windRect.left = over / 2 - 88;
- windRect.bottom = down / 2 + 10;
- windRect.right = over / 2 + 88;
- }
-
- void main(void)
- {
- long ticks;
-
- InitMacintosh();
- InitSpinner ();
-
- //• Humongus main event loop!
- while (! Button ())
- Rotate ();
-
-
- //• Ooops! You clicked!
- InitCursor ();
- SetPort (ibbWind = NewWindow(0L, &windRect, "\p", true,
- plainDBox, (WindowPtr) -1L, true, 0));
- MoveTo (4, 14);
- DrawString ("\pAn itty bitty bytes™ demo!");
- while (! Button ())
- ; //• Do nothing.
- }
-
- //• --------------------------------------------------------------- •//
- //• NOTE: You could use GetMouse and have call Rotate if the mouse
- //• is in your window and InitCursor if it is not. Or, in various
- //• parts of the window, or whatever.
-